package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzZiyuan;
import com.ruoyi.system.service.IDzZiyuanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源Controller
 * 
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/system/ziyuan")
public class DzZiyuanController extends BaseController
{
    @Autowired
    private IDzZiyuanService dzZiyuanService;

    /**
     * 查询资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzZiyuan dzZiyuan)
    {
        startPage();
        List<DzZiyuan> list = dzZiyuanService.selectDzZiyuanList(dzZiyuan);
        return getDataTable(list);
    }

    /**
     * 导出资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:export')")
    @Log(title = "资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzZiyuan dzZiyuan)
    {
        List<DzZiyuan> list = dzZiyuanService.selectDzZiyuanList(dzZiyuan);
        ExcelUtil<DzZiyuan> util = new ExcelUtil<DzZiyuan>(DzZiyuan.class);
        util.exportExcel(response, list, "资源数据");
    }

    /**
     * 获取资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:query')")
    @GetMapping(value = "/{zyId}")
    public AjaxResult getInfo(@PathVariable("zyId") Long zyId)
    {
        return AjaxResult.success(dzZiyuanService.selectDzZiyuanByZyId(zyId));
    }

    /**
     * 新增资源
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:add')")
    @Log(title = "资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzZiyuan dzZiyuan)
    {
        return toAjax(dzZiyuanService.insertDzZiyuan(dzZiyuan));
    }

    /**
     * 修改资源
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:edit')")
    @Log(title = "资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzZiyuan dzZiyuan)
    {
        return toAjax(dzZiyuanService.updateDzZiyuan(dzZiyuan));
    }

    /**
     * 删除资源
     */
    @PreAuthorize("@ss.hasPermi('system:ziyuan:remove')")
    @Log(title = "资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zyIds}")
    public AjaxResult remove(@PathVariable Long[] zyIds)
    {
        return toAjax(dzZiyuanService.deleteDzZiyuanByZyIds(zyIds));
    }
}
